package cn.looov.demo.future.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.looov.demo.future.service.FutureService;

@RestController
@RequestMapping("/future")
public class FutureController {

	@GetMapping("/1")
	public Object test1(String nums) {
		FutureService service = new FutureService();
		String[] split = nums.split(",");
		List<String> asList = Arrays.asList(split);
		List<Integer> n = new ArrayList<Integer>(asList.size());
		asList.forEach(item->{
			n.add(Integer.valueOf(item));
		});
		List<Future<Integer>> test1 = service.test1(n);
		List<Integer> list1 = new ArrayList<Integer>(asList.size());
		test1.forEach(item->{
			try {
				list1.add(item.get());
			} catch (InterruptedException | ExecutionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		});
		return list1;
	}
}
